package com.java46;

import com.java46.bean.Personnel;
import com.java46.mapper.PersonnelMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.io.IOException;
import java.io.InputStream;

public class Entrance {

    public static void main(String[] args) throws IOException {
        // 读取mybatis-config文件
//        InputStream inputStream = Resources.getResourceAsStream("xxx");
        new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
        // 创建SqlSessionFactory
        SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(inputStream);

        // 拿到会话对象
        SqlSession sqlSession = sessionFactory.openSession();

        // 通过会话对象得到mapper代理类
        PersonnelMapper mapper = sqlSession.getMapper(PersonnelMapper.class);

        Personnel personnel = new Personnel();
        personnel.setPersonnelAccount("yyy");
        personnel.setPersonnelName("张张");
        personnel.setPersonnelPwd("999979");
        personnel.setPersonnelType(1);

        mapper.insert(personnel);

        sqlSession.close();
    }
}
